# Contributor: TBK <alpine@jjtc.eu>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: TBK <alpine@jjtc.eu>
pkgname=tree-sitter
pkgver=0.20.10
pkgrel=1
# https://github.com/tree-sitter/tree-sitter/issues/2387
_gitrev=0e4ff0bb27edf37b76fc7d35aa768b02cf4392ad
pkgdesc="Incremental parsing system for programming tools"
url="https://tree-sitter.github.io/"
license="MIT"
arch="all"
depends_dev="jq" # needed for abuild-tree-sitter
makedepends="bash"
checkdepends="nodejs"
subpackages="
	$pkgname-static
	$pkgname-dev
	$pkgname-grammars::noarch
	"
source="https://github.com/tree-sitter/tree-sitter/archive/$_gitrev/tree-sitter-$_gitrev.tar.gz
	abuild-tree-sitter
	"
builddir="$srcdir/tree-sitter-$_gitrev"
# tests require git cloning remote fixtures
# also for cli/wasm only
options="!check"

build() {
	# static & shared lib
	make

	# TODO - build wasm bindings
	# wasm bindings
	#script/build-wasm
}

package() {
	make DESTDIR="$pkgdir" PREFIX=/usr install

	install -Dm755 "$srcdir"/abuild-tree-sitter -t "$pkgdir"/usr/bin/
	# Prepare directory for grammars provided by other aports.
	mkdir -p "$pkgdir"/usr/lib/tree-sitter
}

dev() {
	default_dev

	amove usr/bin/abuild-tree-sitter
}

grammars() {
	pkgdesc="Meta package for pulling in all tree-sitter grammars"
	depends=""

	mkdir -p "$subpkgdir"
}

sha512sums="
b96beadd21938c4807ef8a8a3f4f4391f4fc859c74579972b4493f728c4acbd40004a6ef37ada2b50dd7d38352e0809a7900a85eae1b9445acf520754431025b  tree-sitter-0e4ff0bb27edf37b76fc7d35aa768b02cf4392ad.tar.gz
b76cdd81ce5ba53330d44c0036b11637d546b7995608af8de8696a102fe04cabf6bf23cf256fc5d4d75f5224c9eb6ba3161b537e5f8cb0e0658ff6fc4822c343  abuild-tree-sitter
"
